package cn.edu.hbu.redline;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class BoardListActivity extends ListActivity {

	private ListView lv = null;
	String[] hrefs = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.boardlist);
		lv = (ListView) findViewById(android.R.id.list);

		Intent intent = getIntent();
		// Bundle bundle = intent.getExtras();
		// Log.i(LoginActivity.TAG, bundle.toString());// NullPointerException
		// char[] title = intent.getCharArrayExtra("list");
		String topic = intent.getStringExtra("list");
		// Log.i(LoginActivity.TAG, topic.toString());

		String href = intent.getStringExtra("href");
		// Log.i(LoginActivity.TAG, href);

		hrefs = href.split(" ");
//		Log.i(LoginActivity.TAG, hrefs[0]);
//		Log.i(LoginActivity.TAG, hrefs[1]);
//		 Log.i(LoginActivity.TAG, hrefs[2]);
//		 Log.i(LoginActivity.TAG, hrefs[3]);
		// Log.i(LoginActivity.TAG, hrefs[4]);
		// Log.i(LoginActivity.TAG, hrefs[5]);
		// Log.i(LoginActivity.TAG, hrefs[6]);

		String title = intent.getStringExtra("title");
		String body = intent.getStringExtra("body");

		// Select the board name and set the name into the label of the Activity
		setTitle(title);

		String[] topics = topic.split(" ");
		List<String> topicList = new ArrayList<String>();
		for (String str : topics) {
			topicList.add(String.valueOf(str));
		}

		lv.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_expandable_list_item_1, topicList));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent intent = new Intent();
		intent.putExtra("position", position);
		intent.putExtra("href", hrefs);
		intent.setClass(BoardListActivity.this, ForumDisplayActivity.class);
		startActivity(intent);
	}
}
